<?php
/**
 * 活动-用户管理
 * @copyright (c) Seer All Rights Reserved
 */

require_once 'globals.php';

$Activity_Model = new Activity_Model();
$action = $_POST['action'];
$mode = $_POST['mode'];
$wx_openid = isset($_REQUEST['wx_openid']) ? $_REQUEST['wx_openid'] : '';
$activity_id = isset($_REQUEST['activity_id']) ? $_REQUEST['activity_id'] : '';

$user_name = isset($_REQUEST['user_name']) ? $_REQUEST['user_name'] : '';
$activity_name = isset($_REQUEST['activity_name']) ? $_REQUEST['activity_name'] : '';
$handled = isset($_REQUEST['handled']) ? $_REQUEST['handled'] : '';
$handled = $handled==9?"":$handled;
$page = $_REQUEST['pid'] ? $_REQUEST['pid'] : '1';

$addUrl = $wx_openid ? "&wx_openid={$wx_openid}" : '';
$addUrl .= $activity_id ? "&activity_id={$activity_id}" : '';
$addUrl .= $user_name ? "&user_name={$user_name}" : '';
$addUrl .= $activity_name ? "&activity_name={$activity_name}" : '';
$addUrl .= $handled ? "&handled={$handled}" : '';

//显示活动-用户(活动-用户一览表检索)
if ($action == '' ) {
	$pwd = '用户-活动一览';
	$uasNum = $Activity_Model->getUasNum($wx_openid,$card_id,$handled);
	$uas = $Activity_Model->getUasForAdmin($wx_openid,$activity_id,$handled,$page);

	$pageurl =  pagination($uasNum, Option::get('admin_perpage_num'), $page, "activity_user_list.php?{$addUrl}&pid=");
	include View::getView('header');
	require_once View::getView('activity/activity_user_list');
	include View::getView('footer');View::output();
}

// 用户-活动删除
if ($action == 'delete' ) {
	$uas = isset($_POST['ids']) ? $_POST['ids'] : array();
	$Activity_Model->deleteUa($uas);
	seerDirect("./activity_user_list.php?active_del=1{$addUrl}&pid={$page}");
}

// 用户-活动 信息编辑
if ($action == 'update') {;
	$ID = $_POST['ID'];
	$state = $_POST['state'];

	$Activity_Model->updateUa($ID,$state);
	seerDirect("./activity_user_list.php?active_update{$state}=1&{$addUrl}&pid={$page}");
}
